package com.zy.openchat.core.model.user;

import android.os.Parcel;
import android.os.Parcelable;
import android.text.TextUtils;

import org.apache.commons.lang3.StringUtils;

import java.io.Serializable;

public class MobileContactInfo implements Parcelable , Serializable {
    public String phone_number;
    public String first_name;
    public String last_name;
    public long user_id;


    public void setName(String name){
        if(TextUtils.isEmpty(name)){
            first_name = "";
            last_name = "";
            return;
        }
        if(name.length()>1){
            first_name = name.substring(0,1);
            last_name = name.substring(1,name.length());
        }else {
            first_name = name;
            last_name = "";
        }

    }

    public String displayName() {
        return (StringUtils.isEmpty(first_name) ? "" : first_name) + (StringUtils.isEmpty(last_name) ? "" : last_name);
    }



    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        dest.writeString(this.phone_number);
        dest.writeString(this.first_name);
        dest.writeString(this.last_name);
        dest.writeLong(this.user_id);
    }

    public void readFromParcel(Parcel source) {
        this.phone_number = source.readString();
        this.first_name = source.readString();
        this.last_name = source.readString();
        this.user_id = source.readLong();
    }

    public MobileContactInfo() {
    }

    protected MobileContactInfo(Parcel in) {
        this.phone_number = in.readString();
        this.first_name = in.readString();
        this.last_name = in.readString();
        this.user_id = in.readLong();
    }

    public static final Creator<MobileContactInfo> CREATOR = new Creator<MobileContactInfo>() {
        @Override
        public MobileContactInfo createFromParcel(Parcel source) {
            return new MobileContactInfo(source);
        }

        @Override
        public MobileContactInfo[] newArray(int size) {
            return new MobileContactInfo[size];
        }
    };
}
